//
//  HMComposeButton.swift
//  MicroBlog
//
//  Created by Apple on 16/9/27.
//  Copyright © 2016年 Apple. All rights reserved.
//

import UIKit
//自定义撰写菜单按钮
class HMComposeButton: UIButton {
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //重写高亮效果,修复按钮点击动画出现按钮偏移的bug
    override var isHighlighted: Bool {
        get {
            return false
        } set {
            
        }
    }
    
    private func setupUI() {
        titleLabel?.textAlignment = .center
        imageView?.contentMode = .center
        titleLabel?.font = UIFont.systemFont(ofSize: 14)
        self.setTitleColor(UIColor.gray, for: .normal)
    }
    
    //调整子控件位置
    override func layoutSubviews() {
        super.layoutSubviews()
        //设置图片大小
        imageView?.width = width
        imageView?.height = width
        imageView?.y = 0
        //设置文字大小
        titleLabel?.width = width
        titleLabel?.height = height - width
        //调整文字位置为图片底部
        titleLabel?.y = width
        titleLabel?.x = 0
    }

}
